#include "terrainpropertiesui.h"
#include "ui_terrainpropertiesui.h"
#include <QFileDialog>

TerrainPropertiesUI::TerrainPropertiesUI(QWidget *parent) :
    QWidget(parent),
    m_ui(new Ui::TerrainPropertiesUI)
{
    m_ui->setupUi(this);
}

void TerrainPropertiesUI::browseFile()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this,
			tr("Select Object File"),
			QString("."),
			tr("ViBos Terrain Files(*.vibt);;All Files(*.*)"),
			&selectedFilter,
			options);
	if (fileName.isEmpty())
		return ;

	m_ui->fileLineEdit->setText(fileName);
	spinnersChanged();
}

void TerrainPropertiesUI::spinnersChanged()
{
	float scale = m_ui->scaleSpinBox->value();
	QColor tCol = m_ui->colorFrame->currentColor();
	geom::Vector3D disp(m_ui->dispXSpinbox->value()/100,m_ui->dispYSpinbox->value()/100,m_ui->dispZSpinbox->value()/100);
	geom::Vector3D vCol(tCol.redF(),tCol.greenF(),tCol.blueF());
	slotsdata::GroundProperties properties(m_ui->fileLineEdit->text().toStdString(), scale , disp, vCol );
	emit(groundDataChanged(properties));
}

TerrainPropertiesUI::~TerrainPropertiesUI()
{
    delete m_ui;
}

void TerrainPropertiesUI::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
